package com.pipe.servicebase.handler;

import cn.hutool.core.util.IdUtil;
import com.pipe.commonutils.R;
import com.pipe.servicebase.exception.PipeException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;


/**
 * @ClassName GlobalExceptionHandler
 * @Author HETAO
 * @Date 2020/7/16 19:15
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
    @ExceptionHandler(PipeException.class)
    public R error(PipeException e) {
        String simpleUUID = IdUtil.simpleUUID();
        log.error(e.getMessage()+"流水号id:{}",simpleUUID);
        e.printStackTrace();
        return R.error().message(e.getMsg()+"流水号:"+simpleUUID);
    }


    @ExceptionHandler(Exception.class)
    public R error(Exception e) {
        String simpleUUID = IdUtil.simpleUUID();
        e.printStackTrace();
        log.error(e.getMessage()+"流水号id:{}",simpleUUID);
        return R.error().message(e.getMessage()+"流水号:"+simpleUUID);
    }
}
